//
//  LWTextView.m
//  1.28  weibo
//
//  Created by mac on 15/2/7.
//  Copyright (c) 2015年 mac. All rights reserved.
//

#import "LWTextView.h"

@interface LWTextView ()

@property (nonatomic,weak) UILabel *textF;
@end

@implementation LWTextView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // 1.创建用于显示提醒文本的Label
        UILabel *placeholderLabel = [[UILabel alloc] init];
        placeholderLabel.numberOfLines = 0;
        placeholderLabel.text = @"abcdefg123456789";
        [placeholderLabel sizeToFit];
        placeholderLabel.x = 5;
        placeholderLabel.y = 7;
        // 设置字体大小
        self.font = [UIFont systemFontOfSize:15];
        placeholderLabel.font = self.font;
        //        placeholderLabel.backgroundColor = [UIColor greenColor];
        [self addSubview:placeholderLabel];
        self.textF = placeholderLabel;
        
        // 2.监听文本框输入事件
        //        self.delegate = self;
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChange) name:UITextViewTextDidChangeNotification object:nil];
    }
    return self;
}

- (void)textChange
{
    
    self.textF.hidden = (self.text.length > 0);
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)setPlacegoder:(NSString *)placegoder
{
    _placegoder = [placegoder copy];
    
    self.textF.text = _placegoder;
    [self.textF sizeToFit];
}

- (void)setFont:(UIFont *)font
{
    [super setFont:font];
    self.textF.font = font;
    [self.textF sizeToFit];
}
@end